package hos.http;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>Title: RetrofitParameter </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-04-13 12:49
 */
public class HttpParam {

    String key;
    Object value;
    boolean encoded;

    public HttpParam(String key, Object value) {
        this(key, value, false);
    }

    public HttpParam(String key, Object value, boolean encoded) {
        this.key = key;
        this.value = value;
        this.encoded = encoded;
    }

    public String getKey() {
        return key;
    }

    public Object getValue() {
        return value;
    }

    public boolean isEncoded() {
        return encoded;
    }

    public static List<HttpParam> create(Map<String, Object> map) {
        return create(map,false);
    }

    public static List<HttpParam> create(Map<String, Object> map, boolean encoded) {
        if (map == null) {
            return new ArrayList<>();
        }
        List<HttpParam> httpParamList = new ArrayList<>();
        Set<String> keyset = map.keySet();
        for (String key : keyset) {
            httpParamList.add(new HttpParam(key, map.get(key), encoded));
        }
        return httpParamList;
    }

    public String toJson() {
        return "{\"" + key
                + "\" : \"" + value
                + "\", \"key\" : \""
                + key + "\","
                + "\"value\" : \""
                + value + "\","
                + " \"encoded\" : \""
                + encoded + "\"" +
                "}";
    }

    @Override
    public String toString() {
        return "HttpParam{" +
                "key='" + key + '\'' +
                ", value=" + value +
                ", encoded=" + encoded +
                '}';
    }
}
